package com.htd.erp.web;

import java.util.Collection;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;

import org.apache.commons.lang3.StringUtils;

import com.htd.erp.model.NamedEntity;

@Named
@ApplicationScoped
public class StringUtilsDecorator {
	
	public String abbreviate(String str, int maxWidth) {
		return StringUtils.abbreviate(str, maxWidth);
	}
	
	public String join(Collection<NamedEntity> namedEntities, CharSequence charSequence) {
		if(namedEntities == null || namedEntities.isEmpty()) {
			return "";
		}
		StringBuilder sb = new StringBuilder();
		for(NamedEntity entity : namedEntities) {
			sb.append(charSequence).append(entity.getName());
		}
		return sb.substring(charSequence.length());
	}
}
